<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="银联商户id" prop="mid">
      <el-input v-model="dataForm.mid" placeholder="银联商户id"></el-input>
    </el-form-item>
    <el-form-item label="账单号" prop="billNo">
      <el-input v-model="dataForm.billNo" placeholder="账单号"></el-input>
    </el-form-item>
    <el-form-item label="商户订单编号" prop="merOrderId">
      <el-input v-model="dataForm.merOrderId" placeholder="商户订单编号"></el-input>
    </el-form-item>
    <el-form-item label="账单时间" prop="billDate">
      <el-input v-model="dataForm.billDate" placeholder="账单时间"></el-input>
    </el-form-item>
    <el-form-item label="订单状态" prop="billStatus">
      <el-input v-model="dataForm.billStatus" placeholder="订单状态"></el-input>
    </el-form-item>
    <el-form-item label="订单秒速" prop="billDesc">
      <el-input v-model="dataForm.billDesc" placeholder="订单秒速"></el-input>
    </el-form-item>
    <el-form-item label="订单总金额" prop="totalAmount">
      <el-input v-model="dataForm.totalAmount" placeholder="订单总金额"></el-input>
    </el-form-item>
    <el-form-item label="账单创建时间" prop="billCreateTime">
      <el-input v-model="dataForm.billCreateTime" placeholder="账单创建时间"></el-input>
    </el-form-item>
    <el-form-item label="支付通知id" prop="notifyId">
      <el-input v-model="dataForm.notifyId" placeholder="支付通知id"></el-input>
    </el-form-item>
    <el-form-item label="状态" prop="state">
      <el-input v-model="dataForm.state" placeholder="状态"></el-input>
    </el-form-item>
    <el-form-item label="报文全文" prop="receiveMsg">
      <el-input v-model="dataForm.receiveMsg" placeholder="报文全文"></el-input>
    </el-form-item>
    <el-form-item label="数据创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="数据创建时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          mid: '',
          billNo: '',
          merOrderId: '',
          billDate: '',
          billStatus: '',
          billDesc: '',
          totalAmount: '',
          billCreateTime: '',
          notifyId: '',
          state: '',
          receiveMsg: '',
          createTime: ''
        },
        dataRule: {
          mid: [
            { required: true, message: '银联商户id不能为空', trigger: 'blur' }
          ],
          billNo: [
            { required: true, message: '账单号不能为空', trigger: 'blur' }
          ],
          merOrderId: [
            { required: true, message: '商户订单编号不能为空', trigger: 'blur' }
          ],
          billDate: [
            { required: true, message: '账单时间不能为空', trigger: 'blur' }
          ],
          billStatus: [
            { required: true, message: '订单状态不能为空', trigger: 'blur' }
          ],
          billDesc: [
            { required: true, message: '订单秒速不能为空', trigger: 'blur' }
          ],
          totalAmount: [
            { required: true, message: '订单总金额不能为空', trigger: 'blur' }
          ],
          billCreateTime: [
            { required: true, message: '账单创建时间不能为空', trigger: 'blur' }
          ],
          notifyId: [
            { required: true, message: '支付通知id不能为空', trigger: 'blur' }
          ],
          state: [
            { required: true, message: '状态不能为空', trigger: 'blur' }
          ],
          receiveMsg: [
            { required: true, message: '报文全文不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '数据创建时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/collection/collectionorderinfo/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.mid = data.collectionOrderInfo.mid
                this.dataForm.billNo = data.collectionOrderInfo.billNo
                this.dataForm.merOrderId = data.collectionOrderInfo.merOrderId
                this.dataForm.billDate = data.collectionOrderInfo.billDate
                this.dataForm.billStatus = data.collectionOrderInfo.billStatus
                this.dataForm.billDesc = data.collectionOrderInfo.billDesc
                this.dataForm.totalAmount = data.collectionOrderInfo.totalAmount
                this.dataForm.billCreateTime = data.collectionOrderInfo.billCreateTime
                this.dataForm.notifyId = data.collectionOrderInfo.notifyId
                this.dataForm.state = data.collectionOrderInfo.state
                this.dataForm.receiveMsg = data.collectionOrderInfo.receiveMsg
                this.dataForm.createTime = data.collectionOrderInfo.createTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/collection/collectionorderinfo/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'mid': this.dataForm.mid,
                'billNo': this.dataForm.billNo,
                'merOrderId': this.dataForm.merOrderId,
                'billDate': this.dataForm.billDate,
                'billStatus': this.dataForm.billStatus,
                'billDesc': this.dataForm.billDesc,
                'totalAmount': this.dataForm.totalAmount,
                'billCreateTime': this.dataForm.billCreateTime,
                'notifyId': this.dataForm.notifyId,
                'state': this.dataForm.state,
                'receiveMsg': this.dataForm.receiveMsg,
                'createTime': this.dataForm.createTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
